<template>
	<view class="content">
		<view :class="show ? 'fade-in' : 'fade-out'">
			<view class="top">
				<image :src="userInfo.userAvatar" mode=""></image>
				<text class="name">{{userInfo.nickname}}</text>
				<text class="label">共有{{total}}人守护他</text>
			</view>
			<view class="list">
				<view class="li" v-for="(item,index) in gift" :key="index">
					<view class="left">
						<image :src="item.avatar" mode=""></image>
						<text class="t1">{{item.nickname}}</text>
					</view>
					<view class="btn">{{item.month}}</view>
				</view>
			</view>
			<w-load-more ref="wLoadMore"></w-load-more>
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				id: 0,
				page: 1,
				userInfo: '',
				total: 0,
				gift: [],
				show:false


			}
		},
		onLoad(option) {
			this.id = option.id
			this.getList(1)
		},
		onReachBottom() {
			if(this.gift.length < 20) return
			this.page++
			this.$refs['wLoadMore'].setLoading()
			this.getList()
		},
		methods: {
			async getList(loading) {
				try {
					let result = await this.$request({
						loading,
						method: 'post',
						url: '/api/gift/keep_user',
						data: {
							user_id: this.id,
							page: this.page
						}
					});
					let data = result.data.data
					if(this.page == 1){
						this.userInfo = data.userInfo
						this.total = data.gift.total
						this.gift = data.gift.data
						this.show = true
					}else{
						this.gift = this.gift.concat(data.gift.data)
						this.$refs['wLoadMore'].setNomore()
						if(data.gift.data.length == 0){
							this.page--
						}
					}

				} catch (e) {
					//TODO handle the exception
				}

			}
		}
	}
</script>
<style lang="scss" scoped>
	.content {

    padding: 30rpx;
		.top {
			height: 314rpx;
			background: #ffffff;
			border-radius: 20rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			image {
				width: 128rpx;
				height: 128rpx;
				border-radius: 50%;
			}

			.name {
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;
				margin: 13rpx 0 8rpx 0;
			}

			.label {
				font-size: 26rpx;
				font-weight: 400;
				color: #333333;
			}
		}

		.list {
			margin-top: 20rpx;

			.li {
				height: 148rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
        background: #fff;
        padding: 30rpx;
				.left {
					display: flex;
					align-items: center;

					image {
						width: 108rpx;
						height: 108rpx;
						border-radius: 50%;
					}

					.t1 {
						font-size: 30rpx;
						font-weight: 400;
						color: #333333;
						margin-left: 24rpx;
					}
				}

				.btn {
					height: 56rpx;
					background: linear-gradient(180deg, #DB89F5 0%, #834BF4 100%);
					border-radius: 42rpx;
					font-size: 28rpx;
					font-weight: 500;
					color: #FFFFFF;
					padding: 8rpx 24rpx;
				}
			}
		}
	}
</style>
